<template>
  <div class="detail-header">
    <router-link to="/" tag="div" class="header-abs" v-show="absShow">
      <span class="iconfont icon-abs-back">&#xe64d;</span>
    </router-link>
    <div class="header-fixed" v-show="!absShow" :style="opacityStyle">
      <router-link to="/" tag="span">
        <span class="iconfont icon-fixed-back">&#xe64d;</span>
      </router-link>
      景点详情
    </div>
  </div>
</template>

<script>
export default {
  name: 'detail-header',
  data () {
    return {
      absShow: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    fixedHeaderShow () {
      let top = document.documentElement.scrollTop || document.body.scrollTop
      if (top >= 20) {
        let opacity = top / 140
        this.opacityStyle.opacity = opacity > 1 ? 1 : opacity
        this.absShow = false
      } else {
        this.absShow = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.fixedHeaderShow)
  },
  deactivated () {
    window.removeEventListener('scroll', this.fixedHeaderShow)
  }
}
</script>

<style lang="stylus" scoped>
@import '~styles/varibles.styl'
  .header-abs
    position absolute
    left .2rem
    top .2rem
    width .8rem
    height .8rem
    line-height .8rem
    text-align center
    border-radius .4rem
    background-color rgba(0, 0, 0, .8)
    .icon-abs-back
      color #fff
      font-size .4rem
  .header-fixed
    z-index: 2
    position fixed
    left 0
    top 0
    right 0
    height $headerHeight
    line-height $headerHeight
    text-align center
    font-size .32rem
    color #fff
    background-color $bgColor
    .icon-fixed-back
      position absolute
      top 0
      left 0
      width .64rem
      text-align center
      font-size .4rem
      color #fff
</style>
